<?php 
 
namespace Home\Controller;

class ActionLogController extends HomeCoreController {
	
    public $Model = null;

    protected function _initialize() {
        parent::_initialize();
        $this->Model = D('ActionLog');
    }
	
	public function index(){
		if (IS_AJAX) {
			$mark = I('get.mark');
			$this->assign ( 'mark', $mark );
			$search = I('get.search');
			if ($mark) {
                $map[$mark] = array('like', "$search%");
			}
			$page_size = 15;
			$map['model'] = 'Member';
			$count = $this->Model->where($map)->count();
			$Page = new \Think\Page($count, $page_size);
			$list = $this->Model
				->where($map)
				->order("id desc")
				->limit($Page->firstRow . ',' . $Page->listRows)
				->select();
			foreach($list as $key => $v){
				$map['id'] = $list[$key]['action_id'];
				$action = M('Action')->where($map)->find();
				$list[$key]['action_id'] = $action['title'];
				$maps['id'] = $list[$key]['user_id'];
				$action = M('Member')->where($maps)->find();
				$list[$key]['user_id'] = $action['username'];
                $list[$key]['create_time'] = date('Y-m-d H:i:s',$list[$key]['create_time']);
            }
			$str = $this->tojson($list, $count);			
			echo $str;
			exit;
        } else {
			$del = check_rule('Home/ActionLog/del','Home', session(C('AUTH_KEYS')));
			$this->assign('del', $del);
            $this->display();
        }
	}
	
    public function del(){
        $res = M('ActionLog')->where('1=1')->delete();
        if($res !== false){
			echo json_encode(array('info'=>'日志清空成功', 'status'=>'y'));
        }else {
			echo json_encode(array('info'=>'日志清空失败', 'status'=>'n'));
        }
    }	
}